<template>
  <div>
    <el-header>
      <div>
        <i class="el-icon-edit-outline" />
        修改密码
      <!-- <el-button
        v-show="isbindphone"
        type="primary"
        style="margin-left:10px;"
        @click="getCode"
      >{{ content }}</el-button>
      <router-link
        v-show="!isbindphone"
        to="/user/info"
      >
        <span style="color:red">未绑定手机,请先绑定手机!</span>
      </router-link>
      <span style="color:#aaa;font-size:14px;margin-bottom:20px;font-weight:normal;">修改密码前，请点击获取验证码，验证码将发送到{{ phone }},请注意查收。</span> -->
      </div>
    </el-header>

    <div class="editpwd-container">
      <el-row>
        <el-col
          :span="12"
          justify="center"
        >
          <div
            class="login-main"
            style="margin-top:20px"
          >
            <el-form
              ref="dataForm"
              :rules="Rules"
              :model="dataForm"
              label-width="120px"
              style="width: 100%; "
              :inline-message="true"
            >
              <!-- <el-form-item
                prop="SmsCode"
                label="请输入验证码"
              >
                <el-input
                  v-model="dataForm.SmsCode"
                  placeholder="请输入手机验证码"
                  maxlength="6"
                  minlength="6"
                  class="input-with-select"
                />
              </el-form-item> -->
              <el-form-item
                prop="Pwd"
                label="请输入新密码"
              >
                <el-input
                  :key="passwordType"
                  ref="Pwd"
                  v-model="dataForm.Pwd"
                  :type="passwordType"
                  placeholder="请输入您的新密码"
                  name="password"
                  tabindex="2"
                  auto-complete="on"
                  @keyup.enter.native="handleLogin"
                />
              </el-form-item>

              <el-form-item
                prop="Pwd"
                label="请确认新密码"
              >
                <el-input
                  :key="passwordType"
                  ref="Pwd"
                  v-model="dataForm.PwdAgian"
                  :type="passwordType"
                  placeholder="请确认您的新密码"
                  name="password"
                  tabindex="2"
                  auto-complete="on"
                  @keyup.enter.native="handleLogin"
                />
              </el-form-item>
              <el-row
                type="flex"
                align="middle"
                justify="space-between"
                style="width:100%;margin-bottom:30px;margin-top:50px;text-align:center;"
              >
                <el-col justify="center">
                  <el-button
                    :loading="loading"
                    type="primary"
                    style="margin-bottom:30px"
                    @click.native.prevent="resetPassword"
                  >确定</el-button>
                </el-col>
              </el-row>
            </el-form>
          </div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>
<script>
import { editPwd } from '@/api/user/user'
export default {
  data() {
    return {
      isbindphone: false,
      phone: '',
      dataForm: {
        Pwd: '',
        PwdAgian: '',
        SmsCode: ''
      },
      passwordType: 'password',
      Rules: {
        // SmsCode: [{ required: true, trigger: 'blur', message: '请输入验证码' }],
        Pwd: [
          { required: true, trigger: 'blur', message: '请输入登录密码' },
          {
            min: 8,
            message: '登录密码由8-20位数字或字母组成',
            trigger: 'blur'
          },
          {
            max: 20,
            message: '登录密码由8-20位数字或字母组成',
            trigger: 'blur'
          }
        ]
        // password: [{ required: true, trigger: 'blur', validator: validatePassword }]
      },
      loading: false,
      totalTime: 60,
      canClick: true, // 添加canClick
      content: '获取验证码'
    }
  },
  created() {
    // this.getCurrUserInfo()
  },
  methods: {
    // getCurrUserInfo() {
    //   getCurrUserInfo().then(res => {
    //     if (res.Data.Phone) {
    //       this.phone =
    //         res.Data.Phone.length === 11
    //           ? res.Data.Phone.replace(/^(\d{3})\d{4}(\d{4})$/, '$1****$2')
    //           : res.Data.Phone
    //       this.isbindphone = res.Data.Phone.length === 11
    //     }
    //     if (!this.isbindphone) {
    //       Message({
    //         message: '未绑定手机号,请先绑定手机号',
    //         type: 'error',
    //         duration: 5 * 1000
    //       })
    //       this.$router.replace('/user/info')
    //     }
    //   })
    // },
    showPwd() {
      if (this.passwordType === 'password') {
        this.passwordType = ''
      } else {
        this.passwordType = 'password'
      }
      this.$nextTick(() => {
        this.$refs.password.focus()
      })
    },
    // getCode() {
    //   if (!this.canClick) return
    //   this.canClick = false
    //   this.content = this.totalTime + 's后重新发送'
    //   getResetPwdCode()
    //     .then(() => {
    //       Message({
    //         message: '短信已发送',
    //         type: 'success',
    //         duration: 2 * 1000
    //       })
    //       const clock = window.setInterval(() => {
    //         this.totalTime--
    //         this.content = this.totalTime + 's后重新发送'
    //         if (this.totalTime < 0) {
    //           window.clearInterval(clock)
    //           this.content = '重新发送验证码'
    //           this.totalTime = 60
    //           this.canClick = true // 这里重新开启
    //         }
    //       }, 1000)
    //     })
    //     .catch(() => {
    //       this.canClick = true
    //       this.content = '获取验证码'
    //     })
    // },
    resetPassword() {
      this.$refs['dataForm'].validate(valid => {
        if (valid) {
          var tempData = Object.assign({}, this.dataForm)
          editPwd(tempData).then(() => {
            this.$message({
              message: '密码设置成功',
              type: 'success',
              duration: 3 * 1000
            })
            this.$router.push({ path: this.redirect || '/' })
          })
        }
      })
    }
  }
}
</script>
<style lang="scss">

/* reset element-ui css */
.login-container {
  .login-main {
    margin-top: 100px;
  }

  .el-input {
    display: inline-block;
    height: 47px;
    width: 85%;
  }
}
</style>

<style lang="scss" scoped>
.editpwd-container {
  min-height: 100%;
  width: 100%;
  overflow: hidden;
  .login-form {
    position: relative;
    width: 100%;
    padding: 60px 35px 50px;
    margin: 0 auto;
    overflow: hidden;
    background-color: rgba(0, 0, 0, 0.8);
  }

  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;
    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }

  .svg-container {
    padding: 6px 5px 6px 15px;

    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }

  .title-container {
    position: relative;
    .title {
      font-size: 26px;

      text-align: center;
      font-weight: bold;
    }
  }

  .show-pwd {
    font-size: 14px;
    cursor: pointer;
    user-select: none;
    color: #409eff;
  }

  .active {
    color: #fff;
    background-color: #409eff;
    border-color: #409eff;
  }

  .input-grid {
    background-color: rgba(0, 0, 0, 0.7);
    width: 500px;
    height: 550px;
    border-radius: 6px;
    padding: 40px 20px;
  }

  i {
    margin-right: 5px;
  }
}
</style>
